import Promise from "../../utils/es6-promise.js"
module.exports = {
  fetchApi (url,params,method) {
    if (params != null) {
      params = this.moduoParams(params)
    }else {
      params = undefined
    }
    return new Promise((resolve, reject) => {
      wx.request({
        url: `${url}`,
        data: params,
        method: method,
        header: { 'Content-Type': 'application/json' },
        success: function(res){
          if (res.data.status == '1') {
            resolve(res.data.data)
          }else {
            reject(res.data)
          }
        },
        fail: reject
      })
    })
  },
  moduoParams(params) {
  var newParams = {}
  var secret = 'moduo@2017&sfli%87wirioew3^534rj'
  var md5 = require('../../utils/md5.min.js')
  var paramStr = JSON.stringify(params)
  var str = secret + paramStr
  console.log(str)
  var sign = md5(secret + paramStr)

  newParams.apisign = sign;
  newParams['data'] = params
  return newParams
}
}
